<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加数据</title>
</head>
<style type="text/css">
*{padding: 0;margin: 0;}
  .ys1{
  background-color: greenyellow;
  
  }
  .h11{
  width:100%;
  height:100px;
  background-image:url(imge/table.jpg);
  }
  body{
  background-image: url("imge/add.jpg");
  }
</style>
<body>
    <h1 class="h11" align="center">添加书籍</h1>
	<hr>
	<div align="center">
	<form action="${pageContext.servletContext.contextPath}/book.jsp" method="get" name="form1" onsubmit="return wzx()" >
		<table class="ys1">
			<tr>
				<td>书名：</td>
				<td><input type="text" name="name" autofocus></td>
			</tr>
			<tr>
				<td>作者：</td>
				<td><input type="text" name="author"></td>
			</tr>
			<tr>
				<td>出版社：</td>
				<td><input type="text" name="press"></td>
			</tr>
			<tr>
				<td>出版日期：</td>
				<td><input type="text" name="publicationDate" onkeyup="DateLayout(this)"></td>
			</tr>
			<tr>
				<td>价格：</td>
				<td><input type="text" name="price" onkeyup="onlyNumber(this)"></td>
			</tr>
			<tr>
				<td colspan="2" style="text-align: center;">
					<button type="submit">保存</button>

					<button type="button" onclick="window.location.href = 'book.jsp'">取消</button>
				</td>
			</tr>
			<tr>
			   <td>
			     <input type="hidden" name="type" value="add">
			   </td>
			</tr>
		</table>
		</form>
		</div>
		<script type="text/javascript">
		  function wzx() {
			if(form1.name.value==""){
				alert("请输入书名");
				return false;
			}
			if(form1.author.value==""){
				alert("请输入作者");
				return false;
			}
			if(form1.press.value==""){
				alert("请输入出版社");
				return false;
			}
			if (form1.publicationDate.value=="") {
			    	alert("请输入出日期");
			    	return false;
			    }
			if(form1.price.value==""){
				alert("请输入价格");
				return false;
			}
		}
		
		</script>
		<script type="text/javascript">
		    //强制限制只能输入数字
		   function onlyNumber(obj) {
			obj.value = obj.value.replace(/[^\d\.]/g,'');
			obj.value = obj.value.replace(/^\./g,'');
			obj.value = obj.value.replace(/\.{2,}/g,'.');
			obj.value = obj.value.replace('.','$#$').replace(/\./g,'').replace('$#$','.');
		}
		</script>
</body>
</html>